package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.PurchaseApplyOrder;
import com.example.demo.entity.PurchaseOrder;
import com.example.demo.service.PurchaseOrderService;
import com.example.demo.mapper.PurchaseOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【purchase_order】的数据库操作Service实现
* @createDate 2025-01-08 14:17:57
*/
@Service
public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, PurchaseOrder>
    implements PurchaseOrderService{
    @Autowired
    PurchaseOrderMapper purchaseOrderMapper;

    @Override
    public PurchaseOrder selectByInfo(String userId, String trainingId, String orderNumber, String identifyCode,String isPart) {
        QueryWrapper<PurchaseOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(identifyCode!=null){
            queryWrapper.eq("identifyCode",identifyCode);
        }
        if(orderNumber!=null){
            queryWrapper.eq("orderNumber",orderNumber);
        }
        if(isPart!=null){
            queryWrapper.eq("isPart",isPart);
        }
        queryWrapper.orderByDesc("orderTime");
        List<PurchaseOrder> resultList = purchaseOrderMapper.selectList(queryWrapper);
        if (!resultList.isEmpty()) {
            return resultList.get(0); // 这里返回结果列表的第一条记录
        } else {
            return null;
        }
    }

    @Override
    public Integer delete(String userId, String trainingId) {
        QueryWrapper<PurchaseOrder> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("trainingId",trainingId);
        return purchaseOrderMapper.delete(queryWrapper);
    }

    @Override
    public Integer deleteById(Integer id) {
        return purchaseOrderMapper.deleteById(id);
    }
}




